#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
using namespace std;
#include "a.h"
class Date
{
public:
	Date(int year = 1900, int month = 1, int day = 1)
		: _year(year)
		, _month(month)
		, _day(day)
	{
	}

	bool operator<(const Date& d)const
	{
		return (_year < d._year) ||
			(_year == d._year && _month < d._month) ||
			(_year == d._year && _month == d._month && _day < d._day);
	}

	bool operator>(const Date& d)const
	{
		return (_year > d._year) ||
			(_year == d._year && _month > d._month) ||
			(_year == d._year && _month == d._month && _day > d._day);
	}

	friend ostream& operator<<(ostream& _cout, const Date& d);
private:
	int _year;
	int _month;
	int _day;
};

ostream& operator<<(ostream& _cout, const Date& d)
{
	_cout << d._year << "-" << d._month << "-" << d._day;
	return _cout;
}

struct DateLess
{
	bool operator()(const Date* d1, const Date* d2)
	{
		return *d1 < *d2;
	}
};
struct DateGreater
{
	bool operator()(const Date* d1, const Date* d2)
	{
		return *d1 > *d2;
	}
};
//void Test()
//{
//	priority_queue<Date*> q;
//	q.push(&Date(2025, 1, 1)); //临时对象在表达式结束后会被销毁，造成悬空指针，报错
//	q.push(&Date(2025, 2, 1));
//}
template<class T>
bool Less(T left, T right)
{
	return left < right;
}

template<>
bool Less<Date*>(Date* left, Date* right)
{
	return *left < *right;
}

void Test1()
{
	Date d1(2025, 1, 1);
	Date d2(2025, 2, 1);
	cout << Less(d1, d2) << endl;
	cout << Less(new Date(2021, 1, 29), new Date(2022, 4, 1)) << endl;
	Date* p1 = &d1;
	Date* p2 = &d2;
	cout << Less(p1, p2) << endl;
}

template<class T1,class T2>
class Data
{
public:
	Data() {
		cout << "Data<T1,T2>" << endl;
	}
private:
	T1 _a;
	T2 _b;
};

//全特化
template<>
class Data<int, char>
{
public:
	Data() {
		cout << "Data<int,char>" << endl;
	}
private:
	int _a;
	char _b;
};

//偏特化
template<class T1>
class Data<T1, int>
{
public:
	Data() {
		cout << "Data<T1,int>" << endl;
	}
private:
	T1 _a;
	int _b;
};

template<class T2>
class Data<char, T2>
{
public:
	Data() {
		cout << "Data<char,T2>" << endl;
		//cout << typeid(T2).name() << endl;
	}
private:
	int _a;
	T2 _b;
};

template<class T1,class T2>
class Data<T1*, T2*> //偏特化为指针类型
{
public:
	Data() {
		cout << "Data<T1*,T2*>" << endl;
	}
private:
	T1* _a;
	T2* _b;
};

template<class T1,class T2>
class Data<T1&, T2&>
{
public:
	Data(const T1& a,const T2& b)
		:_a(a),
		_b(b)
	{
		cout << "Data<T1&,T2&>" << endl;
	}
private:
	const T1& _a;
	const T2& _b;
};

void Test2()
{
	Data<char, char> d1;
	Data<int, char> d2;
	Data<int, int> d3;
	Data<int*, int*> d5;
	Data<int&, int&> d6(1, 2);
}

template<class T>
struct LessDate {
	//注意：const修饰的是left和right本身
	bool operator()(const T& left, const T& right) const
	{
		return left < right;
	}
};

template<>
struct LessDate<Date*> {
	//特别注意：const修饰的是left和right本身，而不是它们所指向的对象，因为要和主模板保持一致
	bool operator()(Date* const & left, Date* const & right) const
	{
		return *left < *right;
	}
};
void Test3()
{
	Date d1(2025, 1, 1);
	Date d2(2025, 2, 1);
	Date d3(2025, 3, 1);
	Date d4(2025, 4, 1);

	vector<Date> v;
	v.push_back(d1);
	v.push_back(d2);
	v.push_back(d3);
	v.push_back(d4);

	sort(v.begin(), v.end(), LessDate<Date>());
	for (auto& e : v)
	{
		cout << e << endl;
	}
	cout << endl;
	
	vector<Date*> vv;
	vv.push_back(new Date(2025, 1, 1));
	vv.push_back(new Date(2025, 2, 1));
	vv.push_back(new Date(2025, 3, 1));
	vv.push_back(new Date(2025, 4, 1));
	sort(vv.begin(), vv.end(), LessDate<Date*>());
	for (auto& e : vv)
	{
		cout << *e << endl;
	}
	cout << endl;

}
int main()
{
	//Test3();
	cout << Add(1, 2) << endl;
	cout << Add(1.0, 2.0) << endl;
	return 0;
}